package com.ncs.cns.business.service;

import java.util.List;

import android.content.Context;

import com.ncs.cns.business.dao.impl.UserDAO;
import com.ncs.cns.business.to.UserNcs;

public class UserService {
	private UserDAO userDAO;
	public UserService(Context context) {
		userDAO = new UserDAO(context);
	}

	public String getCurrentUser() {
		List<UserNcs> users = userDAO.find();
		if(users!=null && users.size()>0){
			return users.get(0).getUserId();
		}
		return null;
	}
	
	public UserNcs findById(String userid) {
		List<UserNcs> users = userDAO.findById(userid);
		if(users!=null && users.size()>0){
			return users.get(0);
		}
		return null;
	}
	
	public boolean hasUserId() {
		List<UserNcs> users = userDAO.find();
		return users!=null && users.size()>0;
	}

	public void addUserWithUserId(String currentUserId) {
		UserNcs user = new UserNcs(currentUserId);
		userDAO.insert(user);
	}
	
	public void updateUserWithName(String currentUserId,String userName) {
		UserNcs user = new UserNcs(currentUserId);
		user.setUserName(userName);
		userDAO.update(user);
	}
	
	public String getNameById(String currentUserId) {
		UserNcs user = findById(currentUserId);
		if(user!=null){
			return user.getUserName();
		}
		return "";
	}
	
}
